import { Component } from '@angular/core';
import { Http } from '@angular/http';
//Base components
import { AnalystViewModel } from '../../../shared/templates/analystView/analystView.model';
//Services
import { CompanyRiskService } from '../../companyRisk.service';

declare var Modernizr: any;
declare var $: any;

@Component({
    selector: 'summary-analyst-view',
    templateUrl: '../../../shared/templates/analystView/analystView.component.html',
    styleUrls: ['../../../shared/templates/analystView/analystView.component.css']
})
export class AnalystViewSummaryComponent extends AnalystViewModel {
    public currentClusterName: string;
    public riskClusters: any[];

    constructor(
        private riskService: CompanyRiskService,
        private http: Http) {
        super(http);
        this.isMei = false;
    }

    ngOnInit() {
        this.loaded = new Promise<void>((resolve, reject) => {
            this.getCompanyClusters().then(clusters => {
                this.riskClusters = clusters;
                this.riskService.company.then(company => {
                    this.businessModelComment = company.comments.businessModel;
                    this.exposureComment = company.comments.exposure;
                    this.esgRiskManagement = company.comments.esgRiskManagement;
                    this.companyClusterCode = company.assessmentCode;

                    var cluster = this.riskClusters.filter(function (cluster) {
                        return cluster.code == company.assessmentCode;
                    })[0];

                    this.currentClusterName = cluster != undefined ? cluster.name : "N/A";
                    resolve();
                });
            });
        });
    }
}